import React, { Component } from "react";
import { Route } from "react-router-dom";
/**
 * 一般组件和路由组件的最重要的区别是路由组件会收到Router传递过来的props，其中有三个重要的属性：
 *      history:
 *          go(n)
 *          goBack()
 *          goForward()
 *          push(path, state)
 *          replace(path, state)
 *      location:
 *          pathname: "/home"
 *          search: ""
 *          state: undefined
 *      match:
 *          params: {}
 *          path: "/home"
 *          url: "/home"
 * 而一般组件如果不设置任何标签属性，就不会有props
 * About和Home是路由组件
 */
import About from "./pages/About";
import Home from "./pages/Home";
// Header是一般组件
import Header from "./components/Header";
import MyNavLink from "./components/MyNavLink";

import "./App.css";

export default class App extends Component {
    render() {
        return (
            <div>
                <div className="row">
                    <div className="col-xs-offset-2 col-xs-8">
                        <Header />
                    </div>
                </div>
                <div className="row">
                    <div className="col-xs-2 col-xs-offset-2">
                        <div className="list-group">
                            {/* 原生HTML使用a标签跳转页面 */}
                            {/* <a className="list-group-item" href="./about.html">
                                About
                            </a>
                            <a
                                className="list-group-item active"
                                href="./home.html"
                            >
                                Home
                            </a> */}
                            {/* 
                                react-router-dom中使用BrowserRouter/HashRouter+Link切换组件 --- 编写路由链接 
                                如果想实现高亮效果，不能使用Link组件，要使用NavLink
                            */}
                            {/* <Link className="list-group-item" to="/about">
                                About
                            </Link>
                            <Link className="list-group-item" to="/home">
                                Home
                            </Link> */}
                            {/* 由于需要写重复的className和activeClassName，所以需要对NavLink进行封装 */}
                            {/* <NavLink
                                activeClassName="nav-link-active"
                                className="list-group-item"
                                to="/about"
                            >
                                About
                            </NavLink>
                            <NavLink
                                activeClassName="nav-link-active"
                                className="list-group-item"
                                to="/home"
                            >
                                Home
                            </NavLink> */}
                            <MyNavLink to="/about">About</MyNavLink>
                            <MyNavLink to="/home">Home</MyNavLink>
                        </div>
                    </div>
                    <div className="col-xs-6">
                        <div className="panel">
                            <div className="panel-body">
                                {/* 注册路由，注意必须包在Router组件内 */}
                                <Route path="/about" component={About} />
                                <Route path="/home" component={Home} />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        );
    }
}
